/**
 * Created by lvzj on 2015/6/20.
 */

var backofficeUserBehavior = mongoose.model('backoffice_user_behavior');

exports.saveBehavior = function (req, res, next) {

    if (req.session.backOfficeUser != null) {
        var ip = (req.headers['x-forwarded-for'] || '').split(',')[0]
            || req.connection.remoteAddress;
        var uid = req.session.backOfficeUser._id;

        var params = {
            ip: ip,
            userId: uid,
            reqUrl: req.url,
            input: JSON.stringify(req.body)
        };

        var bub = new backofficeUserBehavior(params);

        bub.save();
    }
    next();
};